package com.two.user.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.two.user.service.UserService;
import com.two.user.service.impl.UserServiceImpl;

public class LoginServlet extends HttpServlet{
	
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);     //调用自己的dopost方法
	}
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//设置请求对象的编码格式
		req.setCharacterEncoding("UTF-8");
		//获取传入的账号和密码
		String username = req.getParameter("username");
		String password = req.getParameter("password");
		UserService service = new UserServiceImpl();
		boolean result = service.login(username, password);
		PrintWriter pw = resp.getWriter();
		pw.append(String.valueOf(result));
		pw.flush();
		pw.close();
	}
}

